package com.cjl.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cjl.auth.mapper.SysPostMapper;
import com.cjl.auth.service.SysPostService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cjl.auth.service.SysUserService;
import com.cjl.model.system.SysPost;
import com.cjl.model.system.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 岗位信息表 服务实现类
 * </p>
 *
 * @author cjl
 * @since 2023-03-18
 */
@Service
public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements SysPostService {

    @Autowired
    private SysUserService sysUserService;

    @Override
    public void updateStatus(Long id, Integer status) {
        SysPost sysPost = baseMapper.selectById(id);
        sysPost.setStatus(status);
        baseMapper.updateById(sysPost);
    }

    @Override
    public Map<String, Object> findPostByUserId(Long userId) {
        List<SysPost> sysPostList = baseMapper.selectList(null);
        SysUser sysUser = sysUserService.getById(userId);
        Map<String, Object> map = new HashMap<>();
        map.put("postList", sysPostList);
        if(sysUser != null){
            map.put("postId", sysUser.getPostId());
        }
        return map;
    }
}
